package com.itheima.controller;

import com.itheima.entity.Result;
import com.itheima.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import javax.sql.rowset.serial.SerialArray;
import java.security.Security;

/**
 * 类 名: UserController
 * 描 述:
 * 作 者: 蔡畅
 * 创 建：2019年12月02日
 */
@RestController
@RequestMapping("/user")
public class UserController {
    @RequestMapping("/getUserName")
    public Result getUserName() {
        //从springsecurity上下文
        User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        return Result.success("", user.getUsername());
    }
}
